package com.zhiche.lisa.oms.controller;

import com.zhiche.lisa.core.enums.CommonEnum;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import com.zhiche.lisa.oms.dao.model.OrderItem;
import com.zhiche.lisa.oms.service.IOrderItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/orderItem")
@Api(value = "/orderItem", description = "订单明细",tags={"订单明细"})
public class OrderItemController {

    private static final Logger LOGGER = LoggerFactory.getLogger(OrderItemController.class);

    @Autowired
    private IOrderItemService orderItemService;

    @GetMapping(value = "/getOrderItemById")
    @ApiOperation(value = "根据id得到订单明细", notes = "根据id得到订单明细", produces = MediaType.APPLICATION_JSON_VALUE,response = RestfulResponse.class)
    public RestfulResponse<OrderItem> getOrderItemById(Long id) {
        LOGGER.info("OrderItemController.getOrderItemById（根据id得到明细） params : {} ", id);
        RestfulResponse<OrderItem> result = new RestfulResponse<>(0,"success",null);
        try {
            OrderItem orderItem = orderItemService.selectById(id);
            result.setData(orderItem);
        } catch (BaseException e) {
            LOGGER.error("OrderItemController.getOrderItemById ERROR... ", e);
            result = new RestfulResponse<>(e.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("OrderItemController.getOrderItemById ERROR... ", e);
            result = new RestfulResponse<>(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return result;
    }
    @GetMapping(value = "/queryOrderItem")
    @ApiOperation(value = "/queryOrderItemApi",notes = "根据来源唯一键查询货物订单明细",response = RestfulResponse.class)
    public RestfulResponse<OrderItem>queryOrderItem(String itemSourceKey ){
        LOGGER.info("controller:/OrderItem/queryOrderItem data: {}", itemSourceKey);
        RestfulResponse result = new RestfulResponse(0,"成功",null);
        try {
            OrderItem standardModeList = orderItemService.queryOrderItem(itemSourceKey);
            result.setData(standardModeList);
        }catch (Exception e){
            result.setCode(-1);
            result.setMessage(e.getMessage());
        }
        return result;
    }


}
